import Vue from 'vue';
import $ from '@/common/js/axios';
import store from "@/store/index";
import $alert from 'base/alert/index';
import Router from 'vue-router';
import Index from 'components/index/index';
const Home = () =>
  import( /* webpackChunkName: "home */ 'components/index/home'); //首页
const ResumeDetail = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/ResumeDetail'); // 简历详情
const Resume = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/resume'); //简历
const Vocation = () =>
  import( /* webpackChunkName: "module-vocation" */ 'components/vocation/vocation'); // 查找职位
const PersonUploadPic = () =>
  import( /* webpackChunkName: "module-person" */ 'components/person/uploadPic');

const PersonUser = () =>
  import( /* webpackChunkName: "module-User" */ 'components/person/user/userMy');
const EditDetail = () =>
  import( /* webpackChunkName: "module-User" */ 'components/person/editDetail');

// 简历-新投递
const NewDelivery = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/newDelivery');
// 简历-已邀约
const Invited = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/invited');
// 简历-已收藏
const Collected = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/collected');
// 简历-已拒绝
const Rejected = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/rejected');
// 简历-最近浏览
const Lately = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/lately');

// 简历-邀请面试
const InviteInterview = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/resume/inviteInterview');

//职位- 正在招聘
const InProgress = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/vocation/inProgress');
//职位- 待审核
const ToBeReviewed = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/vocation/toBeReviewed');
//职位- 审核退回
const Return = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/vocation/return');
//职位- 已停招
const StopCall = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/vocation/stopCall');
//职位- 发布职位
const VocationDetail = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/vocation/editDetail');

const JobDetail = () =>
  import( /* webpackChunkName: "module-resume" */ 'components/vocation/jobDetail');

Vue.use(Router);

const router = new Router({
  // mode: 'history',
  // base: '/dist',
  routes: [
    {
      path: '/',
      redirect: '/home',
    },
    {
      path: '/index',
      name: 'index',
      component: Index,
      meta: {
        title: '职业介绍服务'
      },
      children: [{
        path: '/home',
        name: 'home',
        component: Home,
        meta: {
          title: '首页',
          leavel: 1
        },
        beforeEnter(to, from, next) {
          if (to.name == 'home') {
            $.get("/dwgl/dwxxCx").then(res => {
              // 个人信息
              const userInfo = res.returnData.dwxx;
              if (userInfo) {
                store.commit('SET_USER_INFO', {
                  sfshtg: userInfo.sfshtg
                });
              }
              next({
                name: 'home'
              });
              return
            })
          } else {
            next()
          }
          if (from.name !== 'newjobDetail') {
            sessionStorage.setItem("qwgjz", '');
          }
          next();
        },
      },
      {
        path: '/vocation/vocation',
        name: 'vocation',
        component: Vocation,
        meta: {
          title: ' 职位管理',
          leavel: 1
        },
        redirect: '/vocation/vocation/inProgress',
        children: [
          {
            path: 'inProgress',
            name: 'inProgress',
            component: InProgress,
            meta: {
              title: ' 职位管理',
              leavel: 1
            }
          },
          {
            path: 'toBeReviewed',
            name: 'toBeReviewed',
            component: ToBeReviewed,
            meta: {
              title: ' 职位管理',
              leavel: 1
            }
          },
          {
            path: 'return',
            name: 'return',
            component: Return,
            meta: {
              title: ' 职位管理',
              leavel: 1

            }
          },
          {
            path: 'stopCall',
            name: 'stopCall',
            component: StopCall,
            meta: {
              title: ' 职位管理',
              leavel: 1
            }
          }
        ]
      },
      {
        path: '/resume',
        name: 'resume',
        component: Resume,
        meta: {
          title: ' 简历',
          leavel: 1
        }
      }, {
        path: '/person/user',
        name: 'user',
        component: PersonUser,
        meta: {
          title: '我的',
          leavel: 1
        }
      }]
    },
    {
      path: '/vocation/editDetail',
      name: 'vocationDetail',
      component: VocationDetail,
      meta: {
        title: '发布新职位'
      }
    }, {
      path: '/person/editDetail',
      name: 'editDetail',
      component: EditDetail,
      meta: {
        title: '单位信息维护'
      }
    },
    {
      path: '/vocation/jobDetail',
      name: 'jobDetail',
      component: JobDetail,
      meta: {
        title: '职位详情'
      }
    },
    {
      path: '/resume/resumeDetail',
      name: 'resumeDetail',
      component: ResumeDetail,
      meta: {
        title: '简历详情'
      },
    },
    {
      path: '/resume/inviteInterview',
      name: 'inviteInterview',
      component: InviteInterview,
      meta: {
        title: '邀请面试'
      }
    },
    {
      path: '/person/baseInfo/uploadPic',
      name: 'personUploadPic',
      component: PersonUploadPic,
      meta: {
        title: ' 图片上传'
      }
    },
    // 简历相关路由
    {
      path: '/resume/newDelivery',
      name: 'newDelivery',
      component: NewDelivery,
      meta: {
        title: '新投递'
      }
    },
    {
      path: '/resume/invited',
      name: 'invited',
      component: Invited,
      meta: {
        title: '已邀约'
      }
    },
    {
      path: '/resume/collected',
      name: 'collected',
      component: Collected,
      meta: {
        title: '已收藏'
      }
    },
    {
      path: '/resume/rejected',
      name: 'rejected',
      component: Rejected,
      meta: {
        title: '已拒绝'
      }
    },
    {
      path: '/resume/lately',
      name: 'lately',
      component: Lately,
      meta: {
        title: '最近浏览'
      }
    }
  ]
});

router.beforeEach((to, from, next) => {
  if (store.state.userInfo.sfshtg == '0' && (to.name == "resumeDetail" || to.name == 'inviteInterview' || to.name == 'vocationDetail')) {
    $alert('请先维护单位信息！')
    return;
  }
  next()
})

export default router
